package com.example.lin.zyfypt_327ljd.model;

import com.example.lin.zyfypt_327ljd.bean.LoginBean;
import com.example.lin.zyfypt_327ljd.bean.UserBean;
import com.example.lin.zyfypt_327ljd.bean.FocusBean;
import com.example.lin.zyfypt_327ljd.iface.FocusListListener;
import com.example.lin.zyfypt_327ljd.iface.FocusListiface;
import com.example.lin.zyfypt_327ljd.service.FocusListService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import static android.icu.lang.UCharacter.GraphemeClusterBreak.T;

/**
 * Created by lin on 2017/5/29.
 */
//model  获取收藏文章数据
public class FocusListModel implements FocusListiface<UserBean>{
    private Retrofit retrofit;
    private String BASEURL
            ="http://amicool.neusoft.edu.cn/";
    //构造函数
    public FocusListModel()
    {   //使用Retrofit----1
        retrofit=new Retrofit.Builder()
                .baseUrl(BASEURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    public void getResultList(String mod, int page, String sessionID, final FocusListListener listener) {
        FocusListService service
                = retrofit.create(FocusListService.class);
        Call<List<FocusBean<UserBean>>> call
                = service.getFocusList(mod,page,sessionID);
        call.enqueue(new Callback<List<FocusBean<UserBean>>>() {
            @Override
            public void onResponse(Call<List<FocusBean<UserBean>>> call, Response<List<FocusBean<UserBean>>> response) {
                if (response.isSuccessful() && response != null) {
                    listener.onResponse(response.body());
                } else listener.onFail("on response fail");
            }

            @Override
            public void onFailure(Call<List<FocusBean<UserBean>>> call, Throwable t) {
                listener.onFail(t.toString());
            }
        });
    }
}
